980
class Solution {
    int sum0 = 0;
    int row = 0;
    int col = 0;
    int[] start;
    int[] end;
    int ret = 0;
    boolean[][] flag;

    public int uniquePathsIII(int[][] grid) {
        row = grid.length;
        col = grid[0].length;
        flag = new boolean[row][col];

        for (int i = 0; i  row; i++) {
            for (int j = 0; j  col; j++) {
                if (grid[i][j] == 0) {
                    sum0++;
                } else if (grid[i][j] == 1) {
                    start = new int[2];
                    start[0] = i;
                    start[1] = j;
                } else if (grid[i][j] == 2){
                    end = new int[2];
                    end[0] = i;
                    end[1] = j;
                }
            }
        }
        fun(grid, start[0], start[1], 0);
        return ret;
    }

    public void fun(int[][] grid, int x, int y, int tmp) {
        if (x == end[0] && y == end[1] && tmp == sum0) {
            ret++;
            return;
        }
        x++;
        if (x  row && flag[x][y] == false && (grid[x][y] == 0  grid[x][y] == 2)) {
            flag[x][y] = true;
            fun(grid, x, y, grid[x][y] == 0  tmp+1  tmp);
            flag[x][y] = false;
        }
        x -= 2;
        if (x = 0 && flag[x][y] == false && (grid[x][y] == 0  grid[x][y] == 2)) {
            flag[x][y] = true;
            fun(grid, x, y, grid[x][y] == 0  tmp+1  tmp);
            flag[x][y] = false;
        }
        x++;
        y++;
        if (y  col && flag[x][y] == false && (grid[x][y] == 0  grid[x][y] == 2)) {
            flag[x][y] = true;
            fun(grid, x, y, grid[x][y] == 0  tmp+1  tmp);
            flag[x][y] = false;
        }
        y -= 2;
        if (y = 0 && flag[x][y] == false && (grid[x][y] == 0  grid[x][y] == 2)) {
            flag[x][y] = true;
            fun(grid, x, y, grid[x][y] == 0  tmp+1  tmp);
            flag[x][y] = false;
        }
    }
}
给你一个按 非递减顺序 排序的整数数组 nums，返回 每个数字的平方 组成的新数组，要求也按 非递减顺序 排序。
import java.util.Arrays;

class Solution {
    public int[] sortedSquares(int[] nums) {
        for (int i = 0; i < nums.length; i++){
            nums[i] = (int)Math.pow(nums[i], 2);
        }
        Arrays.sort(nums);
        return nums;
    }
}

给你一个长度为 n 的数组 a。
ai 表示从 i 这个位置开始最多能往后跳多少格。
求从 1 开始最少需要跳几次就能到达第 n 个格子。
import java.util.*;


public class Solution {

    public int Jump (int n, int[] A) {
        // write code here
        int min = 0;
        int a1 = 0;
        int a2 = 0;
        int max = 0;
        int len = A.length;
        for (int i = 0; i < len-1; i++){
            a1 = i + A[i];
            max = Math.max(max, a1);
            if (a2 == i){
                a2 = max;
                min++;
            }          
        
        }
        return min;
    }
}